package com.etc.service.impl;

import com.etc.dao.FavoriteOfDao;
import com.etc.pojo.Favorite;
import com.etc.service.FavoriteOfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FavoriteOfServiceImpl implements FavoriteOfService {

    @Autowired
    FavoriteOfDao dao;

    /**
     * 增加视频收藏记录
     * @param favorite
     * @return
     */
    @Override
    public boolean addFavorite(Favorite favorite) {
        return dao.insertFavorite(favorite)>0;
    }

    /**
     * 根据用户编号和视频编号查询数据库以检验用户是否已收藏视频
     * @param userId
     * @param videoId
     * @return
     */
    @Override
    public boolean getFavoriteByVideoIdAndUserId(String userId, int videoId) {
        return dao.queryFavoriteByVideoIdAndUserId(userId,videoId)!=null;
    }

    /**
     * 根据用户编号和视频编号删除收藏记录
     * @param userId
     * @param videoId
     * @return
     */
    @Override
    public boolean deleteFavoriteByVideoIdAndUserId(String userId, int videoId) {
        return dao.deleteFavoriteByVideoIdAndUserId(userId,videoId)>0;
    }
}
